<?php
require_once dirname(__FILE__).'/../lib/BasesfGuardAuthActions.class.php';
/**
 * sfGuardAuth plugin overriden actions
 *
 * @package    symfony
 * @subpackage plugin
 */
class sfGuardAuthActions extends BasesfGuardAuthActions
{


 

 public function executeSignin($request)
  {
    $user = $this->getUser();
    if ($user->isAuthenticated())
    {
      return $this->redirect('@homepage');
    }

    $this->form = new SigninForm();

    if ($request->isMethod('post'))
    {
      $this->form->bind($request->getParameter('signin'));

      if ($this->form->isValid())
      {
        $values = $this->form->getValues();
        $this->getUser()->signin($values['user'], 'on' === $values['remember']);
        $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $request->getReferer());
        
        // права
        if ($this->getUser()->getProfile()->getIsPartner()==1) {
        	$this->getUser()->addCredential('partner');
        	$this->getUser()->addCredential('payment');
        }
        return $this->redirect('' != $signinUrl ? $signinUrl : '@homepage');
      }
    }
    else
    {
      if ($request->isXmlHttpRequest())
      {
        $this->getResponse()->setHeaderOnly(true);
        $this->getResponse()->setStatusCode(401);

        return sfView::NONE;
      }

      $user->setReferer($request->getReferer());

      $module = sfConfig::get('sf_login_module');
      if ($this->getModuleName() != $module)
      {
        return $this->redirect($module.'/'.sfConfig::get('sf_login_action'));
      }

      $this->getResponse()->setStatusCode(401);
    }
  }
    
    


}
